package com.cv.platform.job;

import com.cv.platform.service.comment.CvCommentDislikeService;
import com.cv.platform.service.comment.CvCommentLikeService;
import com.cv.platform.service.comment.CvCommentReplyDislikeService;
import com.cv.platform.service.comment.CvCommentReplyLikeService;
import com.cv.platform.service.video.CvVideoDislikeService;
import com.cv.platform.service.video.CvVideoLikeService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 点赞和踩的任务调度 - 每 30 分钟批量更新 Redis 中的点赞/踩数据至服务器
 *
 * @author Charles_XDXD
 */
@Slf4j
@Component
public class LikeOrDislikeJob {

    @Resource
    private CvVideoLikeService cvVideoLikeService;

    @Resource
    private CvVideoDislikeService cvVideoDislikeService;

    @Resource
    private CvCommentLikeService cvCommentLikeService;

    @Resource
    private CvCommentDislikeService cvCommentDislikeService;

    @Resource
    private CvCommentReplyLikeService cvCommentReplyLikeService;

    @Resource
    private CvCommentReplyDislikeService cvCommentReplyDislikeService;

    /**
     * 同步点赞和踩的数据至数据库【每 30 分钟执行一次】
     * 涉及模块：视频点赞、视频踩、评论点赞、评论踩、评论回复点赞、评论回复踩
     */
    @XxlJob("syncLikeOrDislikeData")
    public void syncLikeOrDislikeData() {
        log.info("[LikeOrDislikeJob] 开始同步点赞和踩的数据至数据库");
        cvVideoLikeService.syncLikeData();
        cvVideoDislikeService.syncDislikeData();
        cvCommentLikeService.syncLikeData();
        cvCommentDislikeService.syncDislikeData();
        cvCommentReplyLikeService.syncLikeData();
        cvCommentReplyDislikeService.syncDislikeData();
        log.info("[LikeOrDislikeJob] 点赞和踩的点赞数据同步更新完毕");
    }

}
